package com.iweb.oasys.dao;

import com.iweb.oasys.component.JdbcConnectionPool;
import com.iweb.oasys.component.JdbcTemplate;
import com.iweb.oasys.entity.User;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao{

    private static UserDao userDao = new UserDaoImpl();

    private UserDaoImpl(){}

    public static UserDao getInstance() {
        return userDao;
    }

    @Override
    public void userExits(User user) throws SQLException {
        /* 允许前端用用户名或者邮箱或者手机号码登录,所以这里的SQL语句中条件是多个 */
        String sql = "select * from user where username=? or email=? or phone=?";
        ResultSet resultSet = JdbcTemplate.query(sql, user.getUsername(), user.getUsername(), user.getUsername());
        if (resultSet.next()) {
            user.setPassword(resultSet.getString("password"));
        }
        JdbcConnectionPool.closeConnection();
    }
}
